#include "NewUser.h"
#include "ui_NewUser.h"
#include <QDebug>



NewUser::NewUser(QWidget *parent, AdminData *newData) :
    QMainWindow(parent),
    ui(new Ui::NewUser)
{
    ui->setupUi(this);
    this->data=newData;

}

NewUser::~NewUser()
{
    delete ui;
}

void NewUser::on_createAccountButton_clicked()
{
    id = ui->IdEdit->text();
    if(ui->viewComboBox->currentIndex()==0){
        AdminErrorDialog *invalidAccount = new AdminErrorDialog(this, "Please choose a valid account type");
        invalidAccount->setModal(true);
        invalidAccount->exec();
    }
    else{
        type = ui->viewComboBox->currentIndex();

    }

    if(id.isEmpty()){
        ui->IdEdit->setPlaceholderText("Enter a valid ID here");
        palette.setColor(QPalette::Text, Qt::red);
        ui->IdEdit->setPalette(palette);
    }
    else if(!id.isEmpty() && type!=0){
        nuser = new User(id, type);
        this->close();
        data->addUser(*nuser);
    }
}

void NewUser::on_cancelButton_clicked()
{
    this->close();


}

void NewUser::on_IdEdit_cursorPositionChanged(int arg1, int arg2)
{
    palette.setColor(QPalette::Text, Qt::black);
    ui->IdEdit->setPalette(palette);
    if(ui->IdEdit->text().isEmpty())
        ui->IdEdit->setCursorPosition(0);
}







